package com.kl.controller;

import com.kl.model.User;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "用户服务相关接口描叙")
public class UserController {

    @GetMapping("findall")
    @ApiOperation(value = "查询所有用户接口",
            notes = "<span style='color:red;'>描叙:</span>&nbsp;&nbsp;用来查询所有用户信息的接口")
    public Map<String, Object> findAll() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("username", "super_lkl");
        map.put("address", "重庆市渝北区");
        return map;
    }

    @PostMapping("save1")
    @ApiOperation(value = "保存用户信息接口1---地址栏传参",
            notes = "<span style='color:red;'>描叙:</span>&nbsp;&nbsp;用来保存用户信息的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户姓名", dataType = "String", defaultValue = "klliu"),
            @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", defaultValue = "123456")
    })
    public void save1(String username, String password) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        System.out.println(map);
    }

    @PostMapping("save2/{username}/{password}")
    @ApiOperation(value = "保存用户信息接口2---路径传参",
            notes = "<span style='color:red;'>描叙:</span>&nbsp;&nbsp;用来保存用户信息的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户姓名", dataType = "String", defaultValue = "klliu", paramType = "path"),
            @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", defaultValue = "123456", paramType = "path")
    })
    public void save2(@PathVariable("username") String username,
                      @PathVariable("password") String password) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        System.out.println(map);
    }

    @PostMapping("save3")
    @ApiOperation(value = "保存用户信息接口3---JSON格式传参",
            notes = "<span style='color:red;'>描叙:</span>&nbsp;&nbsp;用来保存用户信息的接口")
    public void save3(@RequestBody User user) {
        System.out.println(user);
    }

    @PostMapping("save4")
    @ApiOperation(value = "保存用户信息接口4---修改响应码的默认说明",
            notes = "<span style='color:red;'>描叙:</span>&nbsp;&nbsp;用来保存用户信息的接口")
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 404, message = "请求路径不对"),
            @ApiResponse(code = 400, message = "程序不对"),
            @ApiResponse(code = 401, message = "无权限访问"),
            @ApiResponse(code = 500, message = "服务器出错")
    })
    public Map<String, Object> save4(@RequestBody User user) {
        System.out.println(user);
        Map<String, Object> map = new HashMap<>();
        map.put("username", user.getUsername());
        map.put("password", user.getPassword());
        return map;
    }

}
